package edge.display.backend;

import edge.display.backend.MsgReceiver.Mqtt.MqttReceiver;
import edge.display.backend.MsgReceiver.Zmq.ZmqSubscriber;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class Init {

    @Autowired
    MqttReceiver mqttReceiver;

    @Autowired
    ZmqSubscriber zmqSubscriber;

    @PostConstruct
    public void subscribeMQTT() {
        try {
            mqttReceiver.getConnectionMqtt();
            mqttReceiver.subAll();
            System.out.println("[MQTT] successfully subscribed");
        } catch (MqttException e) {
            e.printStackTrace();
        }
    }

    @PostConstruct
    public void subscribeZMQ() {
        try {
            zmqSubscriber.subscribe();
            System.out.println("[ZMQ] successfully subscribed");
        } catch (Exception e) {
            e.printStackTrace();
            //zmqSubscriber.close();
        }
    }
}
